package helperClasses;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Vector;

public class Book implements Serializable, Comparator<Object>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4416380939735989070L;
	
	private String name, author, edition, quality;
	private String ISBN;
	private double price;
	private Member member;

	
	public Book(String name, String author, String edition, String quality, String ISBN,
			Member member, double price)
	{
		this.name = name;
		this.author = author;
		this.edition = edition;
		this.quality = quality;
		this.ISBN = ISBN;
		this.member = member;
		this.price = price;
	}

	public Book() {

	}
	
	public String toString() {
		String s = "Name: " + this.name;
		return s;
		
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((ISBN == null) ? 0 : ISBN.hashCode());
		result = prime * result + ((author == null) ? 0 : author.hashCode());
		result = prime * result + ((edition == null) ? 0 : edition.hashCode());
		result = prime * result + ((member == null) ? 0 : member.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		long temp;
		temp = Double.doubleToLongBits(price);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((quality == null) ? 0 : quality.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Book other = (Book) obj;
		if (ISBN == null) {
			if (other.ISBN != null)
				return false;
		} else if (!ISBN.equals(other.ISBN))
			return false;
		if (author == null) {
			if (other.author != null)
				return false;
		} else if (!author.equals(other.author))
			return false;
		if (edition == null) {
			if (other.edition != null)
				return false;
		} else if (!edition.equals(other.edition))
			return false;
		if (member == null) {
			if (other.member != null)
				return false;
		} else if (!member.equals(other.member))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (Double.doubleToLongBits(price) != Double
				.doubleToLongBits(other.price))
			return false;
		if (quality == null) {
			if (other.quality != null)
				return false;
		} else if (!quality.equals(other.quality))
			return false;
		return true;
	}

	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getAuthor() {
		return author;
	}


	public void setAuthor(String author) {
		this.author = author;
	}


	public String getEdition() {
		return edition;
	}


	public void setEdition(String edition) {
		this.edition = edition;
	}


	public String getQuality() {
		return quality;
	}


	public void setQuality(String quality) {
		this.quality = quality;
	}


	public String getISBN() {
		return ISBN;
	}


	public void setISBN(String isbn) {
		ISBN = isbn;
	}
	
	public Vector<Object> toVector() {
		Vector<Object> vec = new Vector<Object>();
		
		vec.add(this.name);
		vec.add(this.author);
		vec.add(this.edition);
		vec.add(this.quality);
		vec.add(this.ISBN);
		vec.add(new Double(this.price));
		
		return vec;
	}

	@Override
	public int compare(Object o1, Object o2) {
		Book h1 = (Book) o1;
		Book h2 = (Book) o2;
		return h1.toString().compareTo(h2.toString());
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public Member getMember() {
		return member;
	}
}
